using System.Data.Entity.ModelConfiguration;

namespace SecondLevelCaching.Data.Models.Mapping
  {
      public class ProductMap : EntityTypeConfiguration<Product>
      {
          public ProductMap()
          {
              // Primary Key
              this.HasKey(t => t.ProductID);
  
              // Properties
              this.Property(t => t.ProductName)
                  .IsRequired()
                  .HasMaxLength(40);
  
              this.Property(t => t.QuantityPerUnit)
                  .HasMaxLength(20);
  
              // Table & Column Mappings
              this.ToTable("Products");
              this.Property(t => t.ProductID).HasColumnName("ProductID");
              this.Property(t => t.ProductName).HasColumnName("ProductName");
              this.Property(t => t.SupplierID).HasColumnName("SupplierID");
              this.Property(t => t.CategoryID).HasColumnName("CategoryID");
              this.Property(t => t.QuantityPerUnit).HasColumnName("QuantityPerUnit");
              this.Property(t => t.UnitPrice).HasColumnName("UnitPrice");
              this.Property(t => t.UnitsInStock).HasColumnName("UnitsInStock");
              this.Property(t => t.UnitsOnOrder).HasColumnName("UnitsOnOrder");
              this.Property(t => t.ReorderLevel).HasColumnName("ReorderLevel");
              this.Property(t => t.Discontinued).HasColumnName("Discontinued");
  
              // Relationships
              this.HasOptional(t => t.Category)
                  .WithMany(t => t.Products)
                  .HasForeignKey(d => d.CategoryID);
              this.HasOptional(t => t.Supplier)
                  .WithMany(t => t.Products)
                  .HasForeignKey(d => d.SupplierID);
  
          }
      }
  }